<template>
    <div>
        <h3>和为{{num}}</h3>
        <h1>人员列表</h1>
        <input type="text" placeholder="请输入名字" v-model="name">
        <button @click="add">添加</button>
        <button @click="addWang">添加王某</button>
        <button @click="getFirst">看第一个人大名</button>
        <ul>
            <li v-for="p in personList" :key="p.id">{{p.name}}</li>
        </ul>
    </div>
</template>

<script>
import {nanoid} from 'nanoid'
import { mapState } from 'vuex'
    export default {
        name:'person',
        data() {
            return {
                name:''
            }
        },
        computed:{
            ...mapState('personAbout',['personList']),
            ...mapState('countAbout',['num']),

            // personList(){
            //     return this.$store.state.countAbout.personList
            // },
            // num(){
            //     return this.$store.state.countAbout.num

            
        },
        methods: {
            add(){
                const personObj = {
                    id:nanoid(),
                    name:this.name
                }
                this.$store.commit('personAbout/ADDPERSON',personObj)
                this.name = ''
            },
            addWang(){
                 const personObj = {
                    id:nanoid(),
                    name:this.name
                }
                this.$store.dispatch('personAbout/setPersonWang',personObj)
                this.name = ''
            },
            getFirst(){
                alert(this.$store.getters['personAbout/getFirstName'])
            }
        },
        mounted() {
            console.log(this.$store)
        },
    }
</script>

<style>

</style>